﻿using SmartRS.com.vn.smartrs.domain;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SmartRS.com.vn.smartrs.form.menu
{
    public partial class frmAddDanhMuc : Form
    {
        public delegate void GetFoodKind(FoodKind foodKind);
        public event GetFoodKind getFoodKind;

        public delegate void SendFoodKind(FoodKind foodKind);
        public SendFoodKind sendFoodKind;

        private FoodKind foodKind = null;
        public frmAddDanhMuc()
        {
            InitializeComponent();
            sendFoodKind = new SendFoodKind(setFoodKind);
        }

        private void setFoodKind(FoodKind fk)
        {
            foodKind = fk;
        }
        private void btnHoanTat_Click(object sender, EventArgs e)
        {
            if (!txtTenDanhMuc.Text.Trim().Equals(""))
            {
                if (null == foodKind)
                {
                    foodKind = new FoodKind { foodKindName = txtTenDanhMuc.Text.Trim() };
                }
                else
                {
                    foodKind.foodKindName = txtTenDanhMuc.Text.Trim();
                }
                if (getFoodKind != null)
                {
                    getFoodKind(foodKind);
                    this.Close();
                }
                else
                {
                    this.Close();
                }
            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmAddDanhMuc_Load(object sender, EventArgs e)
        {
            if(null != foodKind)
            {
                txtTenDanhMuc.Text = foodKind.foodKindName;
            }
        }
    }
}
